from datetime import datetime
from typing import List, Optional, Dict, Any
from pydantic import BaseModel

class NodeTypeBase(BaseModel):
    type: str
    label: str
    default_properties: Optional[Dict[str, Any]] = None
    icon: Optional[str] = None
    category: Optional[str] = None

class NodeTypeCreate(NodeTypeBase):
    pass

class NodeTypeResponse(NodeTypeBase):
    pass

    class Config:
        from_attributes = True

class ProcessNodeBase(BaseModel):
    node_type: str
    label: str
    properties: Optional[Dict[str, Any]] = None
    position_x: float
    position_y: float

class ProcessNodeCreate(ProcessNodeBase):
    pass

class ProcessNodeResponse(ProcessNodeBase):
    id: int
    process_id: int

    class Config:
        from_attributes = True

class ProcessEdgeBase(BaseModel):
    source_node_id: int
    target_node_id: int
    properties: Optional[Dict[str, Any]] = None

class ProcessEdgeCreate(ProcessEdgeBase):
    pass

class ProcessEdgeResponse(ProcessEdgeBase):
    id: int
    process_id: int

    class Config:
        from_attributes = True

class ProcessVersionBase(BaseModel):
    version_number: str
    data: Dict[str, Any]
    comment: Optional[str] = None

class ProcessVersionCreate(ProcessVersionBase):
    pass

class ProcessVersionResponse(ProcessVersionBase):
    id: int
    process_id: int
    created_at: datetime

    class Config:
        from_attributes = True

class ProcessBase(BaseModel):
    name: str
    description: Optional[str] = None

class ProcessCreate(ProcessBase):
    pass

class ProcessUpdate(BaseModel):
    name: Optional[str] = None
    description: Optional[str] = None
    status: Optional[str] = None

class ProcessResponse(ProcessBase):
    id: int
    status: str
    created_at: datetime
    updated_at: datetime
    user_id: int
    nodes: List[ProcessNodeResponse]
    edges: List[ProcessEdgeResponse]
    versions: List[ProcessVersionResponse]

    class Config:
        from_attributes = True 